home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / term-source.lha / Extras / Source / term-Source.lha / ASCIIPanel.c next >
C/C++ Source or Header  |  1995-06-17  |  10KB  |  454 lines

  1. /*
  2. **    ASCIIPanel.c
  3. **
  4. **    User interface for built-in ASCII transfer routines
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12. enum    {    GAD_BYTES=1000,GAD_INFORMATION,GAD_CHARDELAY,GAD_LINEDELAY,
  13.         GAD_PACING,GAD_QUIET_TRANSFER,GAD_SKIP,GAD_ABORT
  14.     };
  15.  
  16. STATIC struct LayoutHandle    *ASCIIHandle;
  17. STATIC struct List         MessageList;
  18. STATIC LONG             MessageCount;
  19.  
  20. STATIC STRPTR __saveds
  21. ShowTime(struct Gadget *SomeGadget,WORD Level)
  22. {
  23.     return(LocaleSeconds(Level));
  24. }
  25.  
  26. struct Window * __regargs
  27. CreateASCIIWindow(BYTE Send)
  28. {
  29.     struct IBox Bounds;
  30.  
  31.     NewList(&MessageList);
  32.  
  33.     MessageCount = 0;
  34.  
  35.     if(ASCIIHandle = LT_CreateHandleTags(Window -> WScreen,
  36.         LH_LocaleHook,    &LocaleHook,
  37.     TAG_DONE))
  38.     {
  39.         struct Window *PanelWindow;
  40.  
  41.         LT_New(ASCIIHandle,
  42.             LA_Type,    VERTICAL_KIND,
  43.         TAG_DONE);
  44.         {
  45.             LT_New(ASCIIHandle,
  46.                 LA_Type,    VERTICAL_KIND,
  47.                 LA_LabelID,    MSG_V36_0000,
  48.             TAG_DONE);
  49.             {
  50.                 LT_New(ASCIIHandle,
  51.                     LA_Type,        BOX_KIND,
  52.                     LA_ID,            GAD_BYTES,
  53.                     LABX_FirstLabel,    MSG_ASCIIPANEL_BYTES_GAD,
  54.                     LABX_LastLabel,        MSG_ASCIIPANEL_LINES_GAD,
  55.                     LABX_ReserveSpace,    TRUE,
  56.                     LA_Chars,        50,
  57.                 TAG_DONE);
  58.  
  59.                 LT_New(ASCIIHandle,
  60.                     LA_Type,        LISTVIEW_KIND,
  61.                     LA_LabelID,        MSG_ASCIIPANEL_INFORMATION_GAD,
  62.                     LA_LabelPlace,        PLACE_LEFT,
  63.                     LA_ID,            GAD_INFORMATION,
  64.                     LA_Lines,        2,
  65.                     LALV_MaxGrowX,        70,
  66.                     LALV_MaxGrowY,        10,
  67.                     LALV_CursorKey,        TRUE,
  68.                     GTLV_ReadOnly,        TRUE,
  69.                     GTLV_Labels,        &MessageList,
  70.                 TAG_DONE);
  71.  
  72.                 LT_EndGroup(ASCIIHandle);
  73.             }
  74.  
  75.             if(Send)
  76.             {
  77.                 LT_New(ASCIIHandle,
  78.                     LA_Type,        VERTICAL_KIND,
  79.                     LA_LabelID,        MSG_V36_0003,
  80.                     LAGR_LastAttributes,    TRUE,
  81.                 TAG_DONE);
  82.                 {
  83.                     LT_New(ASCIIHandle,
  84.                         LA_Type,        SliderType,
  85.                         LA_LabelID,        MSG_ASCIIPANEL_CHAR_DELAY_GAD,
  86.                         LA_ID,            GAD_CHARDELAY,
  87.                         GTSL_Min,        0,
  88.                         GTSL_Max,        10 * 100,
  89.                         LA_WORD,        &Config -> TransferConfig -> CharDelay,
  90.                         GTSL_LevelFormat,    "%s s",
  91.                         GTSL_DispFunc,        ShowTime,
  92.                     TAG_DONE);
  93.  
  94.                     LT_New(ASCIIHandle,
  95.                         LA_Type,        SliderType,
  96.                         LA_LabelID,        MSG_ASCIIPANEL_LINE_DELAY_GAD,
  97.                         LA_ID,            GAD_LINEDELAY,
  98.                         GTSL_Min,        0,
  99.                         GTSL_Max,        10 * 100,
  100.                         LA_WORD,        &Config -> TransferConfig -> LineDelay,
  101.                         GTSL_LevelFormat,    "%s s",
  102.                         GTSL_DispFunc,        ShowTime,
  103.                     TAG_DONE);
  104.  
  105.                     LT_New(ASCIIHandle,
  106.                         LA_Type,        CYCLE_KIND,
  107.                         LA_LabelID,        MSG_ASCIIPANEL_TEXT_PACING_GAD,
  108.                         LA_ID,            GAD_PACING,
  109.                         LA_UBYTE,        &Config -> TransferConfig -> PacingMode,
  110.                         LACY_FirstLabel,    MSG_ASCIIPANEL_DIRECT_TXT,
  111.                         LACY_LastLabel,        MSG_ASCIIPANEL_KEYDELAY_TXT,
  112.                     TAG_DONE);
  113.  
  114.                     LT_New(ASCIIHandle,
  115.                         LA_Type,        CHECKBOX_KIND,
  116.                         LA_LabelID,        MSG_ASCIIPANEL_QUIET_TRANSFER_GAD,
  117.                         LA_ID,            GAD_QUIET_TRANSFER,
  118.                         LA_BYTE,        &Config -> TransferConfig -> QuietTransfer,
  119.                     TAG_DONE);
  120.  
  121.                     LT_EndGroup(ASCIIHandle);
  122.                 }
  123.  
  124.                 LT_New(ASCIIHandle,
  125.                     LA_Type,VERTICAL_KIND,
  126.                 TAG_DONE);
  127.                 {
  128.                     LT_New(ASCIIHandle,
  129.                         LA_Type,    XBAR_KIND,
  130.                         LAXB_FullSize,    TRUE,
  131.                     TAG_DONE);
  132.  
  133.                     LT_EndGroup(ASCIIHandle);
  134.                 }
  135.  
  136.                 LT_New(ASCIIHandle,LA_Type,HORIZONTAL_KIND,
  137.                     LAGR_SameSize,    TRUE,
  138.                     LAGR_Spread,    TRUE,
  139.                 TAG_DONE);
  140.                 {
  141.                     LT_New(ASCIIHandle,
  142.                         LA_Type,    BUTTON_KIND,
  143.                         LA_LabelID,    MSG_TRANSFERPANEL_SKIP_CURRENT_FILE_GAD,
  144.                         LA_ID,        GAD_SKIP,
  145.                         LABT_ExtraFat,    TRUE,
  146.                     TAG_DONE);
  147.  
  148.                     LT_New(ASCIIHandle,
  149.                         LA_Type,    BUTTON_KIND,
  150.                         LA_LabelID,    MSG_TRANSFERPANEL_ABORT_ENTIRE_TRANSFER_GAD,
  151.                         LA_ID,        GAD_ABORT,
  152.                         LABT_ExtraFat,    TRUE,
  153.                     TAG_DONE);
  154.  
  155.                     LT_EndGroup(ASCIIHandle);
  156.                 }
  157.             }
  158.             else
  159.             {
  160.                 LT_New(ASCIIHandle,
  161.                     LA_Type,    VERTICAL_KIND,
  162.                 TAG_DONE);
  163.                 {
  164.                     LT_New(ASCIIHandle,LA_Type,XBAR_KIND,LAXB_FullSize,TRUE,TAG_DONE);
  165.  
  166.                     LT_EndGroup(ASCIIHandle);
  167.                 }
  168.  
  169.                 LT_New(ASCIIHandle,
  170.                     LA_Type,    HORIZONTAL_KIND,
  171.                 TAG_DONE);
  172.                 {
  173.                     LT_New(ASCIIHandle,
  174.                         LA_Type,    BUTTON_KIND,
  175.                         LA_LabelID,    MSG_TRANSFERPANEL_ABORT_ENTIRE_TRANSFER_GAD,
  176.                         LA_ID,        GAD_ABORT,
  177.                         LABT_ExtraFat,    TRUE,
  178.                     TAG_DONE);
  179.  
  180.                     LT_EndGroup(ASCIIHandle);
  181.                 }
  182.             }
  183.  
  184.             LT_EndGroup(ASCIIHandle);
  185.         }
  186.  
  187.         Bounds . Left    = WindowLeft + Window -> LeftEdge;
  188.         Bounds . Top    = WindowTop + Window -> TopEdge;
  189.         Bounds . Width    = WindowWidth;
  190.         Bounds . Height    = WindowHeight;
  191.  
  192. //        if(PanelWindow = LT_Layout(ASCIIHandle,Send ? LocaleString(MSG_ASCIIPANEL_SENDING_TXT) : LocaleString(MSG_ASCIIPANEL_RECEIVING_TXT),NULL,0,0,IDCMP_CLOSEWINDOW,0,
  193.  
  194.         if(PanelWindow = LT_Layout(ASCIIHandle,Send ? LocaleString(MSG_ASCIIPANEL_SENDING_TXT) : LocaleString(MSG_ASCIIPANEL_RECEIVING_TXT),&Bounds,0,0,IDCMP_CLOSEWINDOW,0,
  195.             LAWN_HelpHook,        &GuideHook,
  196. //            LAWN_Parent,        Window,
  197.             WA_DepthGadget,        TRUE,
  198.             WA_CloseGadget,        TRUE,
  199.             WA_DragBar,        TRUE,
  200.             WA_RMBTrap,        TRUE,
  201.         TAG_DONE))
  202.         {
  203.             ULONG    IntuiLock = LockIBase(NULL);
  204.             BYTE    Activate,Move;
  205.  
  206.             GuideContext(CONTEXT_ASCII);
  207.  
  208.             if(Config -> MiscConfig -> AlertMode == ALERT_SCREEN || Config -> MiscConfig -> AlertMode == ALERT_BEEP_SCREEN)
  209.                 Move = Activate = TRUE;
  210.             else
  211.             {
  212.                 if(IntuitionBase -> ActiveScreen == PanelWindow -> WScreen)
  213.                     Activate = TRUE;
  214.                 else
  215.                     Activate = FALSE;
  216.             }
  217.  
  218.             UnlockIBase(IntuiLock);
  219.  
  220.             if(Move)
  221.             {
  222.                 if(PanelWindow -> WScreen -> LeftEdge > 0)
  223.                 {
  224.                     if(PanelWindow -> WScreen -> TopEdge > 0)
  225.                         MoveScreen(PanelWindow -> WScreen,-PanelWindow -> WScreen -> LeftEdge,-PanelWindow -> WScreen -> TopEdge);
  226.                     else
  227.                         MoveScreen(PanelWindow -> WScreen,-PanelWindow -> WScreen -> LeftEdge,0);
  228.                 }
  229.                 else
  230.                 {
  231.                     if(PanelWindow -> WScreen -> TopEdge > 0)
  232.                         MoveScreen(PanelWindow -> WScreen,0,-PanelWindow -> WScreen -> TopEdge);
  233.                 }
  234.  
  235.                 WindowToFront(PanelWindow);
  236.  
  237.                 ScreenToFront(PanelWindow -> WScreen);
  238.             }
  239.  
  240.             if(Activate)
  241.                 ActivateWindow(PanelWindow);
  242.  
  243.             PushWindow(PanelWindow);
  244.  
  245.             return(PanelWindow);
  246.         }
  247.  
  248.         LT_DeleteHandle(ASCIIHandle);
  249.  
  250.         ASCIIHandle = NULL;
  251.     }
  252.  
  253.     return(NULL);
  254. }
  255.  
  256. VOID __regargs
  257. DeleteASCIIWindow(struct Window *Window,BYTE WaitForIt)
  258. {
  259.     if(WaitForIt && Window && ASCIIHandle)
  260.     {
  261.         struct IntuiMessage    *Message;
  262.         BOOLEAN             Done = FALSE;
  263.         ULONG             MsgClass,
  264.                      MsgQualifier;
  265.         UWORD             MsgCode;
  266.         struct Gadget        *MsgGadget;
  267.         WORD             i;
  268.  
  269.         for(i = GAD_CHARDELAY ; i <= GAD_SKIP ; i++)
  270.             LT_SetAttributes(ASCIIHandle,i,GA_Disabled,TRUE,TAG_DONE);
  271.  
  272.         do
  273.         {
  274.             if(Wait(PORTMASK(Window -> UserPort) | SIG_BREAK) & SIG_BREAK)
  275.                 break;
  276.  
  277.             while(Message = (struct IntuiMessage *)GT_GetIMsg(Window -> UserPort))
  278.             {
  279.                 MsgClass    = Message -> Class;
  280.                 MsgQualifier    = Message -> Qualifier;
  281.                 MsgCode        = Message -> Code;
  282.                 MsgGadget    = (struct Gadget *)Message -> IAddress;
  283.  
  284.                 GT_ReplyIMsg(Message);
  285.  
  286.                 LT_HandleInput(ASCIIHandle,MsgQualifier,&MsgClass,&MsgCode,&MsgGadget);
  287.  
  288.                 if(MsgClass == IDCMP_CLOSEWINDOW || (MsgClass == IDCMP_GADGETUP && MsgGadget -> GadgetID == GAD_ABORT))
  289.                     Done = TRUE;
  290.             }
  291.         }
  292.         while(!Done);
  293.     }
  294.  
  295.     if(Window && ASCIIHandle)
  296.         PopWindow();
  297.  
  298.     if(ASCIIHandle)
  299.     {
  300.         LT_DeleteHandle(ASCIIHandle);
  301.  
  302.         ASCIIHandle = NULL;
  303.     }
  304.  
  305.     if(MessageCount)
  306.     {
  307.         FreeList(&MessageList);
  308.  
  309.         MessageCount = 0;
  310.     }
  311. }
  312.  
  313. VOID __stdargs
  314. AddASCIIMessage(struct Window *Window,STRPTR Message,...)
  315. {
  316.     STATIC UBYTE __far TempBuffer[256];
  317.  
  318.     struct Node    *Node;
  319.     va_list         VarArgs;
  320.  
  321.     va_start(VarArgs,Message);
  322.     VSPrintf(TempBuffer,Message,VarArgs);
  323.     va_end(VarArgs);
  324.  
  325.     if(Node = CreateNode(TempBuffer))
  326.     {
  327.         if(MessageCount == 100)
  328.         {
  329.             FreeVecPooled(RemHead(&MessageList));
  330.  
  331.             MessageCount = 99;
  332.         }
  333.  
  334.         LT_SetAttributes(ASCIIHandle,GAD_INFORMATION,
  335.             GTLV_Labels,~0,
  336.         TAG_DONE);
  337.  
  338.         AddTail(&MessageList,Node);
  339.  
  340.         LT_SetAttributes(ASCIIHandle,GAD_INFORMATION,
  341.             GTLV_Labels,        &MessageList,
  342.             GTLV_Top,        MessageCount,
  343.             GTLV_MakeVisible,    MessageCount,
  344.         TAG_DONE);
  345.  
  346.         MessageCount++;
  347.     }
  348. }
  349.  
  350. VOID __regargs
  351. UpdateASCIIWindow(struct Window *Window,LONG Bytes,LONG MaxBytes,LONG Lines)
  352. {
  353.     if(Bytes != -1)
  354.     {
  355.         UBYTE LocalBuffer[40];
  356.  
  357.         if(MaxBytes)
  358.         {
  359.             LONG Percent = (100 * Bytes) / MaxBytes;
  360.  
  361.             if(Percent > 100)
  362.                 Percent = 100;
  363.  
  364.             if(LocaleBase)
  365.                 SPrintf(LocalBuffer,"%lD (%ld%%)",Bytes,Percent);
  366.             else
  367.                 SPrintf(LocalBuffer,"%ld (%ld%%)",Bytes,Percent);
  368.         }
  369.         else
  370.             SPrintf(LocalBuffer,ConvNumber,Bytes);
  371.  
  372.         LT_SetAttributes(ASCIIHandle,GAD_BYTES,
  373.             LABX_Index,    0,
  374.             LABX_Text,    LocalBuffer,
  375.         TAG_DONE);
  376.     }
  377.  
  378.     if(Lines != -1)
  379.     {
  380.         UBYTE LocalBuffer[40];
  381.  
  382.         SPrintf(LocalBuffer,ConvNumber,Lines);
  383.  
  384.         LT_SetAttributes(ASCIIHandle,GAD_BYTES,
  385.             LABX_Index,    1,
  386.             LABX_Text,    LocalBuffer,
  387.         TAG_DONE);
  388.     }
  389. }
  390.  
  391. BYTE __regargs
  392. HandleASCIIWindow(struct Window *Window)
  393. {
  394.     struct IntuiMessage    *Message;
  395.     ULONG             MsgClass,
  396.                  MsgQualifier;
  397.     UWORD             MsgCode;
  398.     struct Gadget        *MsgGadget;
  399.  
  400.     while(Message = (struct IntuiMessage *)GT_GetIMsg(Window -> UserPort))
  401.     {
  402.         MsgClass    = Message -> Class;
  403.         MsgQualifier    = Message -> Qualifier;
  404.         MsgCode        = Message -> Code;
  405.         MsgGadget    = (struct Gadget *)Message -> IAddress;
  406.  
  407.         GT_ReplyIMsg(Message);
  408.  
  409.         LT_HandleInput(ASCIIHandle,MsgQualifier,&MsgClass,&MsgCode,&MsgGadget);
  410.  
  411.         if(MsgClass == IDCMP_CLOSEWINDOW)
  412.             return(1);
  413.  
  414.         if(MsgClass == IDCMP_MOUSEMOVE)
  415.         {
  416.             SendSetup();
  417.  
  418.             ConfigChanged = TRUE;
  419.         }
  420.  
  421.         if(MsgClass == IDCMP_GADGETUP)
  422.         {
  423.             switch(MsgGadget -> GadgetID)
  424.             {
  425.                 case GAD_PACING:
  426.                 case GAD_CHARDELAY:
  427.                 case GAD_LINEDELAY:
  428.  
  429.                     ASCIISendSetup();
  430.  
  431.                     ConfigChanged = TRUE;
  432.  
  433.                     break;
  434.  
  435.                 case GAD_QUIET_TRANSFER:
  436.  
  437.                     ConfigChanged = TRUE;
  438.  
  439.                     break;
  440.  
  441.                 case GAD_ABORT:
  442.  
  443.                     return(1);
  444.  
  445.                 case GAD_SKIP:
  446.  
  447.                     return(2);
  448.             }
  449.         }
  450.     }
  451.  
  452.     return(0);
  453. }
  454.